﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Agents.Data;

namespace Agents.Agent
{
    //this page the homepage of the agent when he is on his way to a client
    public partial class StartShiftDisplay : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Get the agent who is in the page
            Agents agent = (new Queries()).GetAgentByUserName(Page.User.Identity.Name);

            // Getting the client information
            int clientId = Int32.Parse(Request.QueryString["clientId"]);

            //spiling the clients information onto screen
            Queries queries = new Queries();
            Clients client = queries.GetClient(clientId);
            statusLbl.Text = client.Name;
            phoneLbl.Text = client.Phone;
            addressLbl.Text = client.GetAddress();
            lastOrderLbl.Text = client.LastOrder.ToString();
            contactMenLbl.Text = client.ContactPerson;
        }

        //function allows the agent to end his shift without arriving at the client's address.
        protected void endShiftBtn_Click(object sender, EventArgs e)
        {
            Queries queries = new Queries();

            // Get the agent who is in the page
            Agents agent = queries.GetAgentByUserName(Page.User.Identity.Name);

            // End the agent's shift
            queries.EndShift(agent);

            Response.Redirect("~/Agent/AgentMenu.aspx");
        }

        //function redirects the agent to the switch costumer page
        protected void switchCostumerBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("SwitchCustomer.aspx?clientId=" + Request.QueryString["clientId"]);
        }

        //function redirects the agent to the with costumer page
        protected void withCostumerBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("WithCustomer.aspx?clientId=" + Request.QueryString["clientId"]);
        }
    }
}